package com.example.demo.controller;

import com.example.demo.entity.CourseCategory;
import com.example.demo.service.CourseCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseCategories")
@CrossOrigin
public class CourseCategoryController {

    @Autowired
    private CourseCategoryService courseCategoryService;

    // 新增课程分类
    @PostMapping
    public int insertCourseCategory(@RequestBody CourseCategory courseCategory) {
        return courseCategoryService.insertCourseCategory(courseCategory);
    }

    // 删除课程分类
    @DeleteMapping("/{id}")
    public int deleteCourseCategoryById(@PathVariable int id) {
        return courseCategoryService.deleteCourseCategoryById(id);
    }

    // 修改课程分类
    @PutMapping
    public int updateCourseCategory(@RequestBody CourseCategory courseCategory) {
        return courseCategoryService.updateCourseCategory(courseCategory);
    }


    // 查询课程分类
    @GetMapping("/{id}")
    public CourseCategory selectCourseCategoryById(@PathVariable int id) {
        return courseCategoryService.selectCourseCategoryById(id);
    }

    // 查询所有课程分类
    @GetMapping("list")
    public List<CourseCategory> selectAllCourseCategories() {
        return courseCategoryService.selectAllCourseCategories();
    }
}
